<template>
    <a-modal v-model:visible="modifyVisible" title="修改" @ok="handleOk" :width=680>
        <a-spin size="large" :spinning="modalSpinningPrice" >
            <a-form :form="form" :label-col="{ span: 8 }" :wrapper-col="{ span: 12 }">
                <a-form-item label="短信内容">
                    <a-textarea
                        v-if="!isView"
                        v-model="formState.fdxnr" 
                        placeholder="请输入短信内容"
                        v-decorator="['fdxnr', { initialValue:formState.fdxnr, rules: rules.fdxnr}]"
                        :autosize="{ minRows: 1, maxRows: 100 }" 
                        >
                    </a-textarea>
                    <span v-else>{{ formState.fdxnr }}</span>
                </a-form-item>
                <a-form-item label="通讯录">
                    <a-textarea
                        v-if="!isView"
                        v-model="formState.fjsdx" 
                        placeholder="请输入通讯录"
                        :autosize="{ minRows: 1, maxRows: 100 }" 
                        >
                    </a-textarea>
                    <span v-else>{{ formState.fjsdx }}</span>
                </a-form-item>
                <a-form-item label="自定义对象">
                    <a-textarea
                        v-if="!isView"
                        v-model="formState.fzdydx" 
                        placeholder="请输入自定义对象"
                        :autosize="{ minRows: 1, maxRows: 100 }" 
                        >
                    </a-textarea>
                    <span v-else>{{ formState.fzdydx }}</span>
                </a-form-item>
                <a-form-item label="发送时间">
                    {{ formState.ffssj }}
                </a-form-item>
                <a-form-item label="定时任务时间">
                    <a-date-picker 
                    v-if="!isView" 
                    show-time  
                    format="YYYY-MM-DD HH:mm:ss"
                    placeholder="请选择定时任务时间" 
                    @change="fdsrwsjOnChange"
                    v-model:value="formState.fdsrwsj"
                    />
                    <span v-else>{{ formState.fdsrwsj }}</span>
                </a-form-item>
            </a-form>
        </a-spin>
    </a-modal>
</template>
<script>
import { editUrl } from './service/index'
import moment from 'moment'
export default {
    components:{

    },
    props:{

    },
    data(){
        return{
            formState:{},
            modifyVisible:false,
            form: this.$form.createForm(this, { name: 'coordinated' }),
            isView:true,
            rules:{
                fdxnr: [{
                    required: true,
                    message: '请输入短信内容',
                    trigger: 'blur',
                }],
            }
        }
    },
    watch:{

    },
    computed: {
        modalSpinningPrice(){
            return this.$store.state.permission.modalSpinningPrice
        },
    },
    mounted(){
    },
    methods:{
        getData(val){
            this.isView = val.isView
            this.formState = val
            this.$store.dispatch('UpdateSpinningPrice', {key:true,stateKey:'modalSpinningPrice'})
        },
        fdsrwsjOnChange(){

        },
        handleOk(){
            if(this.isView){
                this.modifyVisible = false
            }else{
                this.form.validateFields((err, values) => {
                    if(!err){
                        this.$store.dispatch('UpdateSpinningPrice', {key:'true',stateKey:'modalSpinningPrice'})
                        this.formState.fdsrwsj = this.formState.fdsrwsj?moment(this.formState.fdsrwsj).format('YYYY-MM-DD HH:mm:ss'):''
                        editUrl(this.formState).then(res=>{
                            if(res.code == 200){
                                this.$store.dispatch('UpdateSpinningPrice', {key:true,stateKey:'modalSpinningPrice'}).then(() => {
                                    this.modifyVisible = false
                                })
                            }else{
                                this.$message.warning(res.message)
                                this.$store.dispatch('UpdateSpinningPrice', {key:false,stateKey:'modalSpinningPrice'})
                            }
                        })
                    }
                })
            }
        }
    }
}
</script>